import {defineConfig, ConfigEnv, loadEnv} from "vite";
import {resolve} from 'path';
import vue from "@vitejs/plugin-vue"
import styleImport, {VantResolve} from "vite-plugin-style-import";

const pathResolve = (dir: string): any => {
    return resolve(__dirname, '.', dir);
};
import sysConf from './src/config/sysConf';

const alias: Record<string, string> = {
    '@': pathResolve('./src/'),
    'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js',
};
const env: any = process.env.NODE_ENV;
export default defineConfig(({command, mode}) => {
    return {
        mode: env,
        plugins: [
            vue(),
            styleImport({
                resolves: [VantResolve()],
            })
        ],
        resolve: {alias},
        server: {
            host: sysConf.devHost,
            port: sysConf.devPort,
            open: true,
        },
        proxy: {
            '/api': {
                target: sysConf[env + 'BaseUrl'],
                ws: true,
                changeOrigin: true,
                // rewrite: (path) => path.replace(/^\/gitee/, ''),
            },
        },
        // css规则
        css:
            {
                postcss: {
                    plugins: [
                        require('autoprefixer')(),
                        require('postcss-pxtorem')({
                            rootValue: sysConf.uiBNum,
                            propList: ['*']
                        })
                    ]
                }
            }
        ,
        // 静态资源输出目录
        assetsDir: 'static',
        // 禁止转base64
        assetsInlineLimit:
            0,
        // 生产时不提供构建目录
        sourcemap: mode === 'development',
        base: command === 'serve' ? '/' : './',
    }

})
